#include "StdAfx.h"
#include "InstanceStudy.h"

CDataHelper::CDataHelper()
{
}

CDataHelper::~CDataHelper()
{
}

CString CDataHelper::ToUnicodeString(char* value)
{
	if( value == NULL )
		return _T("");

	CString strValue(value);
	return strValue;
}
CString CDataHelper::ToUnicodeString(std::string value)
{
	CString strValue(value.c_str());
	return strValue;
}

std::string CDataHelper::ToAnsiString(CString strValue)
{
	std::string value = CT2A(strValue);
	return value;
}
std::string CDataHelper::ToAnsiString(LPCTSTR strValue)
{
	std::string value = CT2A(strValue);
	return value;
}

std::string CDataHelper::ToFormatedDate(const char* date)
{
	if( date == NULL )
		return "";
	if( strlen(date) < 8 )
		return "";

	char formatedDate[11];
	memset(formatedDate,0,sizeof(formatedDate));

	char year[5], month[3], day[3];
	memset(year,0,sizeof(year));
	memset(month,0,sizeof(month));
	memset(day,0,sizeof(day));
	strncpy(year,date,4);
	strncpy(month,date+4,2);
	strncpy(day,date+6,2);

	sprintf(formatedDate,"%s/%s/%s",year,month,day);

	return formatedDate;

}

std::string CDataHelper::ToFormatedTime(const char* time)
{
	if( time == NULL )
		return "";
	if( strlen(time) < 6 )
		return "";

	char formatedTime[9];
	memset(formatedTime,0,sizeof(formatedTime));

	char hour[3], minute[3], second[3];
	memset(hour,0,sizeof(hour));
	memset(minute,0,sizeof(minute));
	memset(second,0,sizeof(second));
	strncpy(hour,time,2);
	strncpy(minute,time+2,2);
	strncpy(second,time+4,2);

	sprintf(formatedTime,"%s:%s:%s",hour,minute,second);

	return formatedTime;

}

std::string CDataHelper::GetCurrentFormatedDate()
{
	CTime t = CTime::GetCurrentTime();

	CString strTime = t.Format("%Y/%m/%d");

	return ToAnsiString(strTime);
}

std::string CDataHelper::GetCurrentDate()
{
	CTime t = CTime::GetCurrentTime();

	CString strTime = t.Format("%Y%m%d");

	return ToAnsiString(strTime);
}

std::string CDataHelper::GetCurrentFormatedTime()
{
	CTime t = CTime::GetCurrentTime();

	CString strTime = t.Format("%H:%M:%S");

	return ToAnsiString(strTime);
}

std::string CDataHelper::GetCurrentTime()
{
	CTime t = CTime::GetCurrentTime();

	CString strTime = t.Format("%H%M%S");

	return ToAnsiString(strTime);
}